package top.buluoluo.userservice.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.buluoluo.commoncore.domain.response.Result;
import top.buluoluo.userservice.dto.request.LoginRequest;
import top.buluoluo.userservice.dto.request.testRequest;
import top.buluoluo.userservice.service.UserService;

import java.util.Map;
@RestController
@RequestMapping("/auth")
@Tag(name = "认证管理", description = "用户登录、注销、令牌刷新等认证相关接口") // 为控制器添加标签和描述
public class AuthController {
    @Autowired
    private UserService userService;
    @Operation(summary = "登录接口", description = "通过用户名和密码进行登录认证，成功则返回JWT令牌和用户信息")
    @PostMapping("/login")
    public Result<Map<String, Object>> login(@RequestBody @Valid LoginRequest loginRequest) {
        return userService.login(loginRequest.getUsername(),loginRequest.getPassword());
    }
    @Operation(summary = "用户退出登录接口", description = "从请求头中解析token，之后拉黑该token")
    @PostMapping("/logout")
    public Result<String> logout(@RequestBody @Valid testRequest tokenLogoutRequest) {
        return userService.logout(tokenLogoutRequest.getToken());
    }
}
